package com.palm.core.util.castor;

public class FloatCastor implements Castor<Float> {
    public static final FloatCastor instance=new FloatCastor();
    private FloatCastor(){};
    @Override
    public Float cast(Object v) {
        if(v==null){
            return 0F;
        }else if(v instanceof Number){
            return ((Number)v).floatValue();
        }else{
            String str = v.toString();
            if(str.isEmpty()||"null".equals(str)||"undefined".equals(str)||"Infinity".equals(str)){
                return 0f;
            }else{
                try {
                    return Float.parseFloat(str);
                }catch (Exception e){
                    return 0f;
                }
            }
        }
    }
}
